// pages/main/index.js
const App = getApp();
// var mock = require('../../utils/mockSdk.js');

Page({
  data: {
    tabType: {
      tabs: [],
      activeIndex: 0
    },
    bannerList: [],
    topicList: [],
    articleList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('options', options);
    var _this = this;

    var _data_in = {};
    if (_this.data.tabType.activeIndex != 0) {
      _data_in.channelId = _this.data.tabType.tabs[_this.data.tabType.activeIndex].channel_id
    }
    this.getMainData(_data_in, _this.data.tabType.activeIndex);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var _this = this;

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  getMainData(data, activeIndex) {
    var _this = this;

    wx.showLoading({ title: 'loading~' });
    App.Api.post('/iNews/getIndexChannels', data)
      .then((data) => {
        wx.hideLoading();
        _this.setData({
          'tabType': {
            'tabs': data.tabType.tabType,
            'activeIndex': activeIndex
          },
          bannerList: data.bannerList,
          topicList: data.topicList,
          articleList: data.articleList
        });
        
        console.log(data.bannerList)
      })
      .catch((error) => {
        console.log('error', error);
        wx.hideLoading();
        App.topTips.showTopTips.call(_this, error.msg);
      })
  },
  eventTabClick(e) {
    var _this = this;
    var _index = e.currentTarget.id;
    var _channelId = e.currentTarget.dataset.channelid
    console.log('currentTarget', e.currentTarget);
    _this.getMainData({
      channelId: _channelId
    }, _index);

  }
 



})